package com.turnengine.client.local.turn.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Get Turn Interval Data Serializer.
 */
public class GetTurnIntervalDataSerializer extends AbstractCommandDataSerializer<Long> implements IGetTurnIntervalDataSerializer {

	/**
	 * Creates a new Get Turn Interval Data Serializer.
	 */
	public GetTurnIntervalDataSerializer() {
		super(GetTurnInterval.COMMAND_ID);
	}

	@Override
	public Long readReturnValue(IDataReader reader) throws IOException {
		Long value = reader.readLongObject(true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, Long value) throws IOException {
		writer.writeLongObject(value, true);
	}

	@Override
	public IExecutableCommand<Long> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();
		int instanceId = reader.readInt();

		// Create object
		GetTurnInterval object = new GetTurnInterval();
		object.setLoginId(loginId);
		object.setInstanceId(instanceId);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<Long> argument) throws IOException {
		GetTurnInterval object = (GetTurnInterval) argument;

		// Get fields
		long loginId = object.getLoginId();
		int instanceId = object.getInstanceId();

		// Write fields
		writer.writeLong(loginId);
		writer.writeInt(instanceId);
	}

	@Override
	public IExecutableCommandResponse<Long> newResponse() {
		return new GetTurnIntervalResponse();
	}
}
